<template>
  <div class="login">
    <el-card class="login-form">
      <div class="title">
        <span>密码登录</span>
      </div>
      <div method="post" >
        <!--输入框-->
        <div class="input-content">
          <!--autoFocus-->
          <div>
            <input type="text" autocomplete="off" @keyup.enter="login1"
                   placeholder="用户名"  v-model="userName" required/>
          </div>

          <div style="margin-top: 16px">
            <input type="password" @keyup.enter="login1"
                   autocomplete="off" placeholder="登录密码"  v-model="password" required maxlength="32"/>
          </div>
        </div>

        <!--提示信息-->
        <el-alert
                :closable="false"
                v-if="message"
                :title="message"
                type="error">
        </el-alert>

        <!--登入按钮-->
        <div style="text-align: center">
          <button type="submit" class="enter-btn" @click="login1" >登录</button>
        </div>

        <div class="foor">
<!--          <input class="left" type="checkbox" name="rememb"/><span>记住密码</span>-->
<!--          <div class="right"><span>忘记密码 ?</span></div>-->
        </div>
      </div>
    </el-card>

    <img class="background" src="@/assets/img/login.jpg" alt="">

  </div>

</template>

<script>
  import {apiIogin} from '../request/api'

  export default {
    name: "login",
    data() {
      return {
        userName: '',
        password: '',
        message: ''
      }
    },
    methods: {
      login1(){
        apiIogin({userName: this.userName,password:this.password}).then(res =>{
          if (res.code === 20002){
            this.message = res.message
          } else {
            this.$store.dispatch('loginVue',{
            token: res.data[2],
            userId: res.data[0],
            userType: res.data[1]})
            this.$router.push('/');
            this.$message('登录成功');
          }

          console.log(this.$store.state.token)
          console.log(res)
        }).catch(res => {
          console.log('错误：'+res)
        })
      }
    }
  }
</script>

<style scoped>
  .login {
    margin: 150px 0 300px;
    display: flex;
    flex-direction: row;
  }

  .background {
    width: 481px;
    height: 321px;
    margin-top: 80px;
    margin-left: 250px;
    transform: rotate(-20deg);
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.2)
  }

  /*form样式*/

  .title {
    width: 100%;
    height: 40px;
    line-height: 40px;
    margin-bottom: 40px;
  }

  .title span {
    font-size: 25px;
    color: #cacaca;
  }

  .login-form {
    width: 440px;
    height: 400px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
  }

  .title-msg span {
    font-size: 12px;
    color: #707472;
  }

  .input-content {
    width: 100%;
    height: 120px;
  }

  .input-content input {
    width: 330px;
    height: 40px;
    border: 1px solid #dad9d6;
    background: #ffffff;
    padding-left: 10px;
    padding-right: 10px;
  }

  .enter-btn {
    width: 350px;
    height: 40px;
    margin: 15px 0 40px 0;
    color: #fff;
    background: #0bc5de;
    line-height: 40px;
    text-align: center;
    border: 0px;
  }

  .foor{
    width: 100%;
    height: auto;
    color: #9b9c98;
    font-size: 12px;
    margin-top: 20px;
  }

  .enter-btn:hover {
    cursor:pointer;
    background: #1db5c9;
  }

  .foor div:hover {
    cursor:pointer;
    color: #484847;
    font-weight: 600;
  }

  .right{
    float: right;
  }

  .left {
    float: left;
  }

</style>
